﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CDB.LinqModel.Data;
using CDB.LinqData;
using CDB.LinqModel;
using System.Web.Services;

public partial class _Default : System.Web.UI.Page
{
    #region Variable Declration
    IDataRepository _dataObject = new DataRepository();
    static IDataRepository dataObject = new DataRepository();
    Testimonial testimonial;
    List<Testimonial> testimonials = new List<Testimonial>();
    New news;
    List<New> newss = new List<New>();
    Banner banner;
    List<Banner> banners = new List<Banner>();
    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //FillTestimonials();
            //FillLatestNews();
            FillBanners();
        }
    }
    
    //private void FillLatestNews()
    //{
    //    news = new New(_dataObject);
    //    newss = news.GetAllNews();

    //    if (newss != null)
    //    {
    //        rptLatestNews.DataSource = newss;
    //        rptLatestNews.DataBind();
    //    }
    //}
    private void FillBanners()
    {
        banner = new Banner(_dataObject);
        banners = banner.GetAllBanners();

        if (banners != null)
        {
            for (int i = 0; i < banners.Count; i++)
            {
                topbanners.InnerHtml += "<li><div class=\"bannerImage\"><img style='width:930px !important; height:303px !important;' src='banners/" + banners[i].ImageName + "' /></div></li>";
            }
        }
    }

    [WebMethod()]
    public static string NewsLetterSubscription(string emailAddress)
    {
        string rString;

        var subscription = new CDB.LinqModel.Subscription(dataObject);
        subscription.Email = emailAddress;

        subscription.GetSubscriptionByEmail();
        if (subscription.Id != 0)
            rString = "<strong>Oh snap!!</strong> You have already subscribed to our newsletter and useful tips.";
        else
        {
            subscription.Create();
            rString = "<strong>Well done!!</strong> You have subscribed to our newsletter and useful tips.";
        }

        return rString;
    }
    [WebMethod()]
    public static string checkLogin(string userName, string password)
    {
        string rString;

        User user = new User(dataObject);
        user.UserName = userName;
        user.Password = password;

        if (user.checkUserLogin())
        {
            rString = "OK";
        }
        else
        {
            rString = "ERROR";
        }
        
        return rString;
    }
}